home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / HYP / C-D / DartmouthXCMDs.cpt / Dartmouth XCMDs Vol 1&2 / card_11229.txt < prev    next >
Text File  |  1989-02-26  |  14KB  |  535 lines

  1. -- card: 11229 from stack: in
  2. -- bmap block id: 11379
  3. -- flags: 0000
  4. -- background id: 8327
  5. -- name: AuxWindow
  6. ----- HyperTalk script -----
  7. on opencard
  8.   set the visible of field 1 to false -- background field
  9.   set the scroll of card field 1 to 0
  10.   set the scroll of card field 2 to 0
  11.   set the visible of button "close windows" to false
  12. end opencard
  13. on closecard
  14.   set the visible of field 1 to true
  15. end closecard
  16.  
  17.  
  18. -- part 5 (field)
  19. -- low flags: 01
  20. -- high flags: 2007
  21. -- rect: left=18 top=32 right=290 bottom=384
  22. -- title width / last selected line: 0
  23. -- icon id / first selected line: 0 / 0
  24. -- text alignment: 0
  25. -- font id: 20
  26. -- text size: 12
  27. -- style flags: 0
  28. -- line height: 16
  29. -- part name: XCMD Text
  30.  
  31.  
  32. -- part 6 (button)
  33. -- low flags: 00
  34. -- high flags: 8003
  35. -- rect: left=304 top=299 right=321 bottom=425
  36. -- title width / last selected line: 0
  37. -- icon id / first selected line: 0 / 0
  38. -- text alignment: 1
  39. -- font id: 0
  40. -- text size: 12
  41. -- style flags: 0
  42. -- line height: 16
  43. -- part name: Show LSC Source
  44. ----- HyperTalk script -----
  45. on mouseUp
  46.   get the visible of card field "source"
  47.   set the visible of card field "source" to not it
  48.   if it is false then
  49.     set the name of me to "Hide LSC Source"
  50.   else
  51.     set the name of me to "Show LSC Source"
  52.   end if
  53. end mouseUp
  54.  
  55.  
  56.  
  57. -- part 9 (button)
  58. -- low flags: 00
  59. -- high flags: 0000
  60. -- rect: left=394 top=38 right=132 bottom=484
  61. -- title width / last selected line: 0
  62. -- icon id / first selected line: 0 / 0
  63. -- text alignment: 1
  64. -- font id: 0
  65. -- text size: 12
  66. -- style flags: 0
  67. -- line height: 16
  68. -- part name: Copy This 
  69. ----- HyperTalk script -----
  70. on mouseUp
  71.   global window1,window2
  72.   if window1 is empty then
  73.     put "150,140,250,240" into aRect
  74.     auxWindow "open","aux 1",aRect
  75.     put the result into window1
  76.     put the rect of button 2 into aRect
  77.     auxWindow "use",window1,arect
  78.     if window2 is not empty then
  79.       set the visible of card button swap to true
  80.     end if
  81.   else
  82.     put "Its window is already up!"
  83.   end if
  84.   set the visible of button "close windows" to true
  85. end mouseUp
  86.  
  87.  
  88.  
  89. -- part 10 (button)
  90. -- low flags: 00
  91. -- high flags: 0000
  92. -- rect: left=395 top=141 right=240 bottom=485
  93. -- title width / last selected line: 0
  94. -- icon id / first selected line: 0 / 0
  95. -- text alignment: 1
  96. -- font id: 0
  97. -- text size: 12
  98. -- style flags: 0
  99. -- line height: 16
  100. -- part name: This Too!
  101. ----- HyperTalk script -----
  102. on mouseUp
  103.   global window2,window1
  104.   if window2 is empty then
  105.     put "300,140,400,240" into aRect
  106.     auxWindow "open","aux 2",aRect
  107.     put the result into window2
  108.     put the rect of button 3 into aRect
  109.     auxWindow "use",window2,arect
  110.     if window1 is not empty then
  111.       set the visible of card button swap to true
  112.     end if
  113.   else
  114.     put "Its window is already up!"
  115.   end if
  116.   set the visible of button "close windows" to true
  117. end mouseUp
  118.  
  119.  
  120.  
  121. -- part 11 (button)
  122. -- low flags: 80
  123. -- high flags: 8003
  124. -- rect: left=59 top=299 right=322 bottom=170
  125. -- title width / last selected line: 0
  126. -- icon id / first selected line: 0 / 0
  127. -- text alignment: 1
  128. -- font id: 0
  129. -- text size: 12
  130. -- style flags: 0
  131. -- line height: 16
  132. -- part name: Close Windows
  133. ----- HyperTalk script -----
  134. on mouseUp
  135.   global window1,window2
  136.   if window1 is not empty then
  137.     AuxWindow "close",window1
  138.     put empty into window1
  139.   end if
  140.   if window2 is not empty then
  141.     AuxWindow "close",window2
  142.     put empty into window2
  143.   end if
  144.   set the visible of me to false
  145.   set the visible of button "swap" to false
  146.   put empty
  147. end mouseUp
  148.  
  149.  
  150.  
  151. -- part 12 (button)
  152. -- low flags: 80
  153. -- high flags: 8003
  154. -- rect: left=402 top=254 right=275 bottom=478
  155. -- title width / last selected line: 0
  156. -- icon id / first selected line: 0 / 0
  157. -- text alignment: 1
  158. -- font id: 0
  159. -- text size: 12
  160. -- style flags: 0
  161. -- line height: 16
  162. -- part name: Swap
  163. ----- HyperTalk script -----
  164. on mouseUp
  165.   global window1,window2
  166.   if window1 is not empty and window2 is not empty then
  167.     auxwindow "use",window1,the rect of button 3
  168.     auxwindow "use",window2,the rect of button 2
  169.     set the visible of button "swap" to false
  170.   else
  171.     put "You need both windows up to do this."
  172.   end if
  173. end mouseUp
  174.  
  175.  
  176.  
  177. -- part 7 (field)
  178. -- low flags: 81
  179. -- high flags: 0007
  180. -- rect: left=18 top=31 right=292 bottom=488
  181. -- title width / last selected line: 0
  182. -- icon id / first selected line: 0 / 0
  183. -- text alignment: 0
  184. -- font id: 3
  185. -- text size: 10
  186. -- style flags: 0
  187. -- line height: 13
  188. -- part name: source
  189.  
  190.  
  191. -- part contents for card part 5
  192. ----- text -----
  193. AuxWindow Version 1.0d1
  194. Roger Brown
  195.  
  196. AuxWindow is an XCMD that lets you create a new window that is relatively smart in the HyperCard environment. This XCMD does not do anything especially useful, but can serve as a shell for more elaborate operations. As presented here, AuxWindow lets you create any number of auxiliary windows. For each, you specify a name and a frame rectangle. The window created is of type rDocProc with no go-away box. This is important, because a window nees to be disposed using the XCMD "close" operation so that the window pointer is properly purged. 
  197.  
  198. An auxiliary window can be dragged around and put in front or behind other windows such as the tools and pattern pallettes, desk accessories, and other auxiliary windows. The card window will always stay behind, of course.  HyperCard is very smart about managing windows. An auxiliary window will properly update its contents because they are stored as a WindowPicture. (See the LSC code.) One oddity is that you must click on the title bar to activate one of them. This is HyperCard's doing.
  199.  
  200. The XCMD as presented here allows you to open a window and later close it. The script must maintain the window pointer in a global. For HyperCard versions later than 1.1 this business could be hidden in a global that never appears in a script. 
  201.  
  202. With this version, you can also use a window to hold a drawing. The code calls back to HyperCard to copy a area of the card's paint layer and installs the copy in the aux window using the clipboard. (See the LSC code.)
  203.  
  204. To try it, click on the patterns marked "Copy This!" and "This Too!" on the right side of this card. The patterns you click on will appear in auxiliary windows. Then move them around a bit with other windows present to see what happens. Press the "Swap" button to see the pictures interchange.   Finally, close the windows with by pressing the "Close" button. Look at the scripts of these buttons to see how to use the XCMD.
  205.  
  206. INVOKING XScrollBox
  207.  
  208.    AuxWindow "open",name of window, frame rect of window
  209.        the result must be held in a global, this is the Window Pointer
  210.  
  211.    AuxWindow "use",window pointer global, rectangle to copy
  212.  
  213.    AuxWindow "close", window pointer
  214.  
  215.  
  216. REVISION HISTORY
  217. 1.0d1 7/1/88 add name and frame parameters
  218.  
  219.  
  220. -- part contents for card part 7
  221. ----- text -----
  222. /* AuxWindow1.0d1.c */
  223. /* version 1 add name and location rect in open */
  224. /* floating window for XCMD  */
  225. /* ¬© Trustees of Dartmouth College */
  226. /* written in LightSpeed C  ¬© Think Technologies, Inc */
  227. /* by Roger Brown 7/1/88  Courseware Development Group */
  228.  
  229. /* Creates a floating no go-away window with a picture that is cut
  230.    from a card.
  231.    
  232.     syntax is:
  233.                 AuxWindow "open",name,rectangle of window
  234.                     returns window pointer
  235.                     
  236.                 AuxWindow "use",window pointer,rectangle to copy
  237.                 
  238.                 AuxWindow "close",window pointer
  239.                 
  240. */
  241.  
  242. #include "stddata_ctype.c"
  243. #include "QuickDraw.h"
  244. #include "FontMgr.h"
  245. #include "EventMgr.h"
  246. #include "WindowMgr.h"
  247. #include "MenuMgr.h"
  248. #include "MemoryMgr.h"
  249. #include "ResourceMgr.h"
  250. #include "ToolboxUtil.h"
  251. #include "ControlMgr.h"
  252. #include "DialogMgr.h"
  253. #include "strings.c"
  254. #include "ListMgr.h"
  255. #include "HyperXCmd.h"
  256. #include "XCmdGlue.inc.c"
  257.  
  258.  
  259. #define FALSE 0
  260. #define TRUE 1
  261. #define HORIZ 1
  262. #define VERT  2
  263. #define VISIBLE 1
  264. #define XCMDSetupA4() asm {move.l a4,-(sp)  \
  265.                        move.l a0,a4}
  266.  
  267. #define XCMDRestoreA4() asm { move.l (sp)+,A4 }
  268.  
  269. /* globals */
  270.  
  271. XCmdBlockPtr    gParamPtr;
  272.  
  273. WindowPtr theWindow;    
  274. PicHandle itsPic;
  275.  
  276. Str255 theResult;
  277. Rect windowRect,grabRect;
  278.  
  279. /* return the max of two ints */
  280.  
  281. max(a,b)
  282. int a,b;
  283. {   
  284.     if (a>b) return a;
  285.     return b;
  286. }
  287.  
  288. /* convert a character to upper case */
  289.  
  290. int toupper(c)
  291. char    c;
  292. {
  293.     return( (c>='a')&&(c<='z') ? (c-('a'-'A')) : c );
  294. }
  295.  
  296. /* convert a string to upper case */
  297.  
  298. ucase(s)
  299. char *s;
  300. {
  301.     int i,l;
  302.     l = strlen(s);
  303.     for (i=0;i<l;i++) s[i] = toupper(s[i]);
  304. }
  305.  
  306. /* get a HyperCard item as a numeric value */
  307.  
  308. int GetHCNumberItem(s,i)
  309. char *s;
  310. int i;
  311. /* Get HyperCard comma delimited item i from item list string s. */
  312. {
  313.     int c,len,count,j;
  314.     char temp[32];
  315.     long it;
  316.     
  317.     count = j = 0;
  318.     len = strlen(s);
  319.     for (c=0;c<len;c++) {
  320.         if (s[c]==',') {
  321.             count = count + 1;
  322.             if (count==i) break;
  323.             j = 0;
  324.         }
  325.         else {
  326.             temp[j] = s[c];
  327.             j++;
  328.             if (c==(len-1)) { /* last item, no comma */
  329.                 count = count+1;
  330.                 break;
  331.             }
  332.         }
  333.     }
  334.     if (count < i) strcpy(temp,"");  /* no item there */
  335.     temp[j] = 0;
  336.     CtoPstr(temp);
  337.     StringToNum(temp,&it);
  338.     return (int)it;
  339. }
  340.  
  341.  
  342. /* copy the current card in the given rectangel and make it into a picture */
  343.  
  344. GetMyPicture()
  345. {
  346.     Str255 buildStr;
  347.     char temp[32];
  348.     long len,offset;
  349.  
  350.     strcpy(buildStr,"set lockscreen to true");
  351.     CtoPstr(buildStr);
  352.     SendCardMessage(gParamPtr,buildStr);
  353.     
  354.     strcpy(buildStr,"choose select tool");
  355.     CtoPstr(buildStr);
  356.     SendCardMessage(gParamPtr,buildStr);
  357.     
  358.     strcpy(buildStr,"drag from ");
  359.     NumToString((long)grabRect.left,temp);
  360.     PtoCstr(temp);
  361.     strcat(buildStr,temp);
  362.     strcat(buildStr,",");
  363.     NumToString((long)grabRect.top,temp);
  364.     PtoCstr(temp);
  365.     strcat(buildStr,temp);
  366.     strcat(buildStr," to ");
  367.     NumToString((long)grabRect.right,temp);
  368.     PtoCstr(temp);
  369.     strcat(buildStr,temp);
  370.     strcat(buildStr,",");
  371.     NumToString((long)grabRect.bottom,temp);
  372.     PtoCstr(temp);
  373.     strcat(buildStr,temp);
  374.     CtoPstr(buildStr);
  375.     SendCardMessage(gParamPtr,buildStr);
  376.     
  377.     strcpy(buildStr,"domenu copy picture");
  378.     CtoPstr(buildStr);
  379.     SendCardMessage(gParamPtr,buildStr);
  380.         
  381.     strcpy(buildStr,"choose browse tool");
  382.     CtoPstr(buildStr);
  383.     SendCardMessage(gParamPtr,buildStr);
  384.     
  385.     
  386.     strcpy(buildStr,"set lockscreen to false");
  387.     CtoPstr(buildStr);
  388.     SendCardMessage(gParamPtr,buildStr);
  389.     
  390.     itsPic = (PicHandle)NewHandle(0);
  391.     len = GetScrap((PicHandle)itsPic,'PICT',&offset);
  392.  
  393. }
  394.  
  395. /* create a window on the fly */
  396.  
  397. CreateWindow(name,frame)
  398. char *name;
  399. Rect *frame;
  400. {
  401.     CtoPstr(name);
  402.     theWindow = NewWindow(NULL,frame,name,TRUE,rDocProc,
  403.                 (WindowPtr)-1,FALSE,NULL);
  404. }
  405.  
  406. /* open a window */
  407.  
  408. OpenWindow()
  409. {
  410.     Ptr theRect,theName;
  411.     char theRectStr[32];
  412.     Str255 theNameStr;
  413.     GrafPtr gp;
  414.     Rect windowRect;
  415.         
  416.     theName = *(gParamPtr->params[1]);
  417.     strcpy(theNameStr,theName);
  418.     theRect = *(gParamPtr->params[2]);
  419.     strcpy(theRectStr,theRect);
  420.     
  421.     windowRect.left = GetHCNumberItem(theRectStr,1);
  422.     windowRect.top = GetHCNumberItem(theRectStr,2);
  423.     windowRect.right = GetHCNumberItem(theRectStr,3);
  424.     windowRect.bottom = GetHCNumberItem(theRectStr,4);
  425.     
  426.     CreateWindow(theNameStr,&windowRect);
  427.     NumToString(theWindow,theResult);
  428.     PtoCstr(theResult);     
  429.     ShowWindow(theWindow);
  430.     BringToFront(theWindow);
  431. }
  432.  
  433. /* use the window to present the copied picture */
  434.  
  435. UseWindow()
  436. {
  437.     Ptr theWindowPtr;
  438.     Ptr theRect;
  439.     Rect badRect;
  440.     Str255 wPointer;
  441.     char message[32],theRectStr[32];
  442.     GrafPtr gp;
  443.     
  444.     theWindowPtr = *(gParamPtr->params[1]);
  445.     strcpy(wPointer,theWindowPtr);
  446.     CtoPstr(wPointer);
  447.     StringToNum(wPointer,&theWindow);
  448.     theRect = *(gParamPtr->params[2]);
  449.     strcpy(theRectStr,theRect);
  450.     
  451.     grabRect.left = GetHCNumberItem(theRectStr,1);
  452.     grabRect.top = GetHCNumberItem(theRectStr,2);
  453.     grabRect.right = GetHCNumberItem(theRectStr,3);
  454.     grabRect.bottom = GetHCNumberItem(theRectStr,4);
  455.  
  456.     
  457.     itsPic = GetWindowPic(theWindow);
  458.     if (itsPic != 0L) KillPicture(itsPic);
  459.     GetMyPicture();
  460.     if (GetHandleSize(itsPic) > 0L ) {
  461.         SetWindowPic(theWindow,itsPic);
  462.         GetPort(&gp);
  463.         SetPort(theWindow);
  464.         SetOrigin(grabRect.left,grabRect.top);
  465.         SetPort(theWindow);
  466.         badRect = (*theWindow).portRect;
  467.         InvalRect(&badRect);
  468.         SetPort(gp);
  469.         BringToFront(theWindow);
  470.     }
  471.     NumToString(theWindow,theResult);
  472.     PtoCstr(theResult);     
  473. }
  474.  
  475. /* close the window */
  476.  
  477. CloseWindow()
  478. {
  479.     Ptr theWindowPtr;
  480.     Str255 wPointer;
  481.     
  482.     theWindowPtr = *(gParamPtr->params[1]);
  483.     strcpy(wPointer,theWindowPtr);
  484.     CtoPstr(wPointer);
  485.     StringToNum(wPointer,&theWindow);
  486.     
  487.     itsPic = GetWindowPic(theWindow);
  488.     if (itsPic != 0L) KillPicture(itsPic);
  489.     DisposeWindow(theWindow);
  490.     strcpy(theResult,"0");
  491. }
  492.  
  493. /* branch on the opcode given in param[0] */
  494.  
  495. AuxWindow()
  496. {   
  497.     Ptr theMessage;
  498.     char message[32];
  499.     
  500.     theMessage = *(gParamPtr->params[0]);
  501.     strcpy(message,theMessage);
  502.     ucase(message);
  503.         
  504.     if (strcmp(message,"OPEN")==0) OpenWindow();
  505.     else if (strcmp(message,"USE")==0) UseWindow();
  506.     else if (strcmp(message,"CLOSE")==0) CloseWindow();
  507.     else {        /* undefined message */
  508.         SysBeep(0);
  509.         strcpy(theResult,"Undefined message in clue window XCMD");
  510.     }   
  511. }
  512.  
  513. /* XCMD enty point */
  514.  
  515. pascal void main(paramPtr)
  516. XCmdBlockPtr    paramPtr;
  517. {
  518.     long len;
  519.     Handle resultHandle;
  520.     
  521.     XCMDSetupA4();          /* do this if you have global variables */
  522.     gParamPtr = paramPtr;
  523.     AuxWindow();        /* run the main event loop */
  524.     len = 1+strlen(theResult);
  525.     resultHandle = NewHandle(len);
  526.     HLock(resultHandle);
  527.     BlockMove(theResult,*resultHandle,len);
  528.     HUnlock(resultHandle);
  529.     paramPtr->returnValue = resultHandle;
  530.     XCMDRestoreA4();        /* and this also */
  531.     return;
  532. }
  533.  
  534.  
  535.